﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using HeresyManager.Comunication;

namespace HeresyManager.Careers
{
    [Serializable]
    public class Arbittator : Career
    {

        private Skill[] skills;
        private Talent[] talents;


        public override string Name
        {
            get { return "Arbittator"; }
        }

        public override IEnumerator<Comunicator> Acire(Character c)
        {

            List<Skill> skillList = new List<Skill>();

            skillList.Add(new Skills.SpeakLanguages.SpeakLanguageLowGothic(Skill.SkillLevel.Skilled));
            skillList.Add(new Skills.Literacy(Skill.SkillLevel.Skilled));
            skillList.Add(new Skills.CommonLores.CommonLoreAdeptusArbites(Skill.SkillLevel.Skilled));
            skillList.Add(new Skills.CommonLores.CommonLoreImperium(Skill.SkillLevel.Skilled));
            skillList.Add(new Skills.Inquiry(Skill.SkillLevel.Skilled));


            skills = skillList.ToArray();

            foreach (var s in skills)
            {
                var en = c.AddSkill(s, this);
                while (en.MoveNext())
                    yield return en.Current;
            }




            List<Talent> talentList = new List<Talent>();

            talentList.Add(new Talents.WeaponTraining.BasicWeaponTrainingSP());
            talentList.Add(new Talents.WeaponTraining.MeleeWeaponTrainingPrimitive());

            var choose = new ChooseOne<Talent>("Choose One", new Talents.QuickDraw(), new Talents.RapidReload());
            while (choose.SelectedValue == null)
                yield return choose;
            talentList.Add(choose.SelectedValue);



            talents = talentList.ToArray();

            foreach (var s in talents)
            {
                var en = c.AddTalent(s, this);
                while (en.MoveNext())
                    yield return en.Current;
            }

        }

        public override void DeAcire(Character c)
        {
            foreach (var s in skills)
            {
                c.RemoveSkill(s, this);
            }

            foreach (var item in talents)
            {
                c.RemoveTalent(item, this);
            }
            this.talents = null;
        }


        public override Rank[] Ranks
        {
            get { return new Rank[] { }; }
        }

        public override BackgroundPackage[] BackgroundPackages
        {
            get { return new BackgroundPackage[] { new TheCalixianPatternKillings(), new TheEmptyMenofSinophiaMagna(), new TheRedVaultsofLuggnum() }; }
        }


        #region backgroundPackages
        [Serializable]
        private class TheCalixianPatternKillings : BackgroundPackage
        {

            private bool intelegence;

            private Talent talent;


            public override string Name
            {
                get { return "The Calixian Pattern Killings"; }
            }

            public override int Cost
            {
                get { return 200; }
            }

            public override IEnumerator<Comunicator> Accire(Character c)
            {
                var en = base.Accire(c);
                while (en.MoveNext())
                    yield return en.Current;


                talent = new Talents.Talented(new Skills.Inquiry(Skill.SkillLevel.Skilled));

                en = c.AddTalent(talent, this);
                while (en.MoveNext())
                    yield return en.Current;

                var com = new Comunication.ChooseOne("Choose +5", "Intelegenece", "Perception");
                while (com.SelectedIndex == -1)
                    yield return com;
                intelegence = com.SelectedIndex == 0;
                if (intelegence)
                    c.Int += 5;
                else
                    c.Per += 5;

            }

            public override void DeAccire(Character c)
            {
                base.DeAccire(c);
                c.RemoveTalent(talent, this);
                if (intelegence)
                    c.Int -= 5;
                else
                    c.Per -= 5;
            }
        }

        [Serializable]
        private class TheEmptyMenofSinophiaMagna : BackgroundPackage
        {


            private Talent[] talent;


            private int insanety;

            public override string Name
            {
                get { return "The Empty Men of Sinophia Magna"; }
            }

            public override int Cost
            {
                get { return 100; }
            }



            public override IEnumerator<Comunicator> Accire(Character c)
            {
                var en = base.Accire(c);
                while (en.MoveNext())
                    yield return en.Current;


                var list = new List<Talent>();

                list.Add(new Talents.Hatreds.HatredHeretics());
                list.Add(new Talents.Paranoia());



                talent = list.ToArray();
                foreach (var s in talent)
                {
                    en = c.AddTalent(s, this);
                    while (en.MoveNext())
                        yield return en.Current;
                }


                var rolDie = new RoleDice("Insanaty", Dice.D5);
                while (rolDie.Value == -1)
                    yield return rolDie;
                insanety = rolDie.Value;

                c.InsanityPoints += insanety;
            }

            public override void DeAccire(Character c)
            {
                base.DeAccire(c);
                foreach (var s in talent)
                {
                    c.RemoveTalent(s, this);
                }

                c.InsanityPoints -= insanety;

            }
        }
        [Serializable]
        private class TheRedVaultsofLuggnum : BackgroundPackage
        {


            private Talent[] talent;


            private int insanety;

            public override string Name
            {
                get { return "The Red Vaults of Luggnum"; }
            }

            public override int Cost
            {
                get { return 100; }
            }



            public override IEnumerator<Comunicator> Accire(Character c)
            {
                var en = base.Accire(c);
                while (en.MoveNext())
                    yield return en.Current;

                c.Wp += 3;

                var list = new List<Talent>();

                list.Add(new Talents.Jaded());



                talent = list.ToArray();
                foreach (var s in talent)
                {
                    en = c.AddTalent(s, this);
                    while (en.MoveNext())
                        yield return en.Current;
                }


                var rolDie = new RoleDice("Insanaty", Dice.D5);
                while (rolDie.Value == -1)
                    yield return rolDie;
                insanety = rolDie.Value;

                c.InsanityPoints += insanety;
            }

            public override void DeAccire(Character c)
            {
                base.DeAccire(c);
                c.Wp -= 3;
                foreach (var s in talent)
                {
                    c.RemoveTalent(s, this);
                }

                c.InsanityPoints -= insanety;

            }
        }
        #endregion



        public override int[] WeaponSkillCost
        {
            get { return new int[] { 250, 500, 750, 1000 }; }
        }

        public override int[] BalisticSkillCost
        {
            get { return new int[] { 100, 250, 500, 750 }; }
        }

        public override int[] StrengthCost
        {
            get { return new int[] { 500, 750, 1000, 2500 }; }
        }

        public override int[] ToughnessCost
        {
            get { return new int[] { 100, 250, 500, 500 }; }
        }

        public override int[] AgilityCost
        {
            get { return new int[] { 500, 750, 1000, 2500 }; }
        }

        public override int[] IntelligenceCost
        {
            get { return new int[] { 100, 250, 500, 750 }; }
        }

        public override int[] PerceptionCost
        {
            get { return new int[] { 250, 500, 750, 1000 }; }
        }

        public override int[] WillpowerCost
        {
            get { return new int[] { 250, 500, 750, 1000 }; }
        }

        public override int[] FellowshipCost
        {
            get { return new int[] { 250, 500, 750, 1000 }; }
        }
    }
}
